package PRODUCT.REPORT;

import TOOLS.SQLtool;

public class c_productReport {
	
	SQLtool sql;
	public c_productReport(SQLtool iSql) {
		sql=iSql;
	}
	
	public void newDBsheet() throws Exception {
		String tableName="[production].[schedule]";
		String sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
		try {
			sql.Command(sqlStr);
		} catch (Exception e) {
			if(e.getMessage().equals("-11")) {
				;
			}else {
				throw e;
			}
		}
		sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
				"[scheduleIndex] int IDENTITY(1,1) NOT NULL UNIQUE,\r\n" + 
				"[sequence] int NULL ,\r\n" + 
				"[t_hour] int NULL ,\r\n" + 
				"[createTime] datetime DEFAULT GETDATE() ,\r\n" + 
				"[lastTime] datetime DEFAULT GETDATE() \r\n" + 
				")";
		sql.Command(sqlStr);
		sqlStr="insert [production].[schedule] (sequence,t_hour) values (0,0),(1,1),"
				+ "(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),"
				+ "(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19),"
				+ "(20,20),(21,21),(22,22),(23,23) ";
		sql.Command(sqlStr);
		
		tableName="[production].[stationReport]";
		sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
		try {
			sql.Command(sqlStr);
		} catch (Exception e) {
			if(e.getMessage().equals("-11")) {
				;
			}else {
				throw e;
			}
		}
		sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
				"[stationReportIndex] int NOT NULL UNIQUE,\r\n" + 
				"[stationID] varchar(100) NULL,\r\n" + 
				"[headTime] datetime NULL,\r\n" + 
				"[tailTime] datetime NULL,\r\n" + 
				"[activeOrder] varchar(100) NULL,\r\n" + 
				"[quantity] int NULL ,\r\n" + 
				"[sumQuantity] int NULL ,\r\n" + 
				"[masterOrder] varchar(100) NULL,\r\n" + 
				"[masterNumber] varchar(100) NULL,\r\n" + 
				"[panelOrder] varchar(100) NULL,\r\n" + 
				"[panelNumber] varchar(100) NULL,\r\n" + 
				"[createTime] datetime DEFAULT GETDATE() ,\r\n" + 
				"[lastTime] datetime DEFAULT GETDATE() \r\n" + 
				") ";
		sql.Command(sqlStr);
		
	}
}
